<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <script type="application/javascript" src="js/jquery.min.js"></script>
    <script type="application/javascript" src="js/FileSaver.min.js"></script>
    <script type="application/javascript" src="js/jszip.min.js"></script>
    <title></title>
</head>
<body>
<input type="file" id="file" onchange="handleFiles(this.files)"/>
<p id="p"><p>
<input type="button" value="ck" id="ck">
<input type="button" value="fun" id="fun" onclick="fakeload()">
<input type="file" accept="mt" id="load" style="display: none;"/>
</body>
<script>
    function handleFiles(files) {
    if (files.length) {
        var file = files[0];
        var reader = new FileReader();
        console.info(file.type,/text\/\w+/.test(file.type))
        if (/text\/\w+/.test(file.type)) {
            reader.onload = function() {
                $('<pre>' + this.result + '</pre>').appendTo('body');
            }
            reader.readAsText(file);
        }
    }
}

function download(data, filename, type) {
    var file = new Blob([data], {type: type});
    if (window.navigator.msSaveOrOpenBlob) // IE10+
        window.navigator.msSaveOrOpenBlob(file, filename);
    else { // Others
        var a = document.createElement("a"),
                url = URL.createObjectURL(file);
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();
        setTimeout(function() {
            document.body.removeChild(a);
            window.URL.revokeObjectURL(url);
        }, 0);
    }
}

var metas_zip=new Object()
metas_zip["blocks.xml"]="aaaaaa";
    metas_zip["ren"]="aaaaa";
/*
* 打成一个压缩包
* @metas_zip是一个object key是文件名  value是文件内容
* @filename是压缩包的名字
* */
function metas_save_zip(metas_zip,filename){

     var zip = new JSZip();
    for(var i in metas_zip){
        zip.file(i,metas_zip[i])
    }

    zip.generateAsync({type:"blob"}).then(function(content) {
    // Force down of the Zip file
    saveAs(content, filename);
    });
}



 $('#ck').click(function(){

// Add an top-level, arbitrary text file with contents
        metas_save_zip(metas_zip,"metas_project.mt")

    })

function fakeload(e) {
     var on_load=document.getElementById('load');
     on_load.click();
  }

document.getElementById('load').addEventListener('change', load, false)

 function load(event) {
         var new_zip = new JSZip();
         new_zip.loadAsync(this.files[0]).then(function (zip) {
            new_zip.file("blocks.xml").async("string") // 此处是压缩包中的testTXT.txt文件，以string形式返回其内容，此时已经可以获取zip中的所有文件了
            .then(function (content) {
                // use content
                console.info(content)
            });
         });

 }







</script>

</html>